#if PATROL_ENABLED

  import Foundation
  import XCTest

  private let elementTypeNames = [
    XCUIElement.ElementType.any: "any",
    XCUIElement.ElementType.other: "other",
    XCUIElement.ElementType.application: "application",
    XCUIElement.ElementType.group: "group",
    XCUIElement.ElementType.window: "window",
    XCUIElement.ElementType.sheet: "sheet",
    XCUIElement.ElementType.drawer: "drawer",
    XCUIElement.ElementType.alert: "alert",
    XCUIElement.ElementType.dialog: "dialog",
    XCUIElement.ElementType.button: "button",
    XCUIElement.ElementType.radioButton: "radioButton",
    XCUIElement.ElementType.radioGroup: "radioGroup",
    XCUIElement.ElementType.checkBox: "checkBox",
    XCUIElement.ElementType.disclosureTriangle: "disclosureTriangle",
    XCUIElement.ElementType.popUpButton: "popUpButton",
    XCUIElement.ElementType.comboBox: "comboBox",
    XCUIElement.ElementType.menuButton: "menuButton",
    XCUIElement.ElementType.toolbarButton: "toolbarButton",
    XCUIElement.ElementType.popover: "popover",
    XCUIElement.ElementType.keyboard: "keyboard",
    XCUIElement.ElementType.key: "key",
    XCUIElement.ElementType.navigationBar: "navigationBar",
    XCUIElement.ElementType.tabBar: "tabBar",
    XCUIElement.ElementType.tabGroup: "tabGroup",
    XCUIElement.ElementType.toolbar: "toolbar",
    XCUIElement.ElementType.statusBar: "statusBar",
    XCUIElement.ElementType.table: "table",
    XCUIElement.ElementType.tableRow: "tableRow",
    XCUIElement.ElementType.tableColumn: "tableColumn",
    XCUIElement.ElementType.outline: "outline",
    XCUIElement.ElementType.outlineRow: "outlineRow",
    XCUIElement.ElementType.browser: "browser",
    XCUIElement.ElementType.collectionView: "collectionView",
    XCUIElement.ElementType.slider: "slider",
    XCUIElement.ElementType.pageIndicator: "pageIndicator",
    XCUIElement.ElementType.progressIndicator: "progressIndicator",
    XCUIElement.ElementType.activityIndicator: "activityIndicator",
    XCUIElement.ElementType.segmentedControl: "segmentedControl",
    XCUIElement.ElementType.picker: "picker",
    XCUIElement.ElementType.pickerWheel: "pickerWheel",
    XCUIElement.ElementType.switch: "switch",
    XCUIElement.ElementType.toggle: "toggle",
    XCUIElement.ElementType.link: "link",
    XCUIElement.ElementType.image: "image",
    XCUIElement.ElementType.icon: "icon",
    XCUIElement.ElementType.searchField: "searchField",
    XCUIElement.ElementType.scrollView: "scrollView",
    XCUIElement.ElementType.scrollBar: "scrollBar",
    XCUIElement.ElementType.staticText: "staticText",
    XCUIElement.ElementType.textField: "textField",
    XCUIElement.ElementType.secureTextField: "secureTextField",
    XCUIElement.ElementType.datePicker: "datePicker",
    XCUIElement.ElementType.textView: "textView",
    XCUIElement.ElementType.menu: "menu",
    XCUIElement.ElementType.menuItem: "menuItem",
    XCUIElement.ElementType.menuBar: "menuBar",
    XCUIElement.ElementType.menuBarItem: "menuBarItem",
    XCUIElement.ElementType.map: "map",
    XCUIElement.ElementType.webView: "webView",
    XCUIElement.ElementType.incrementArrow: "incrementArrow",
    XCUIElement.ElementType.decrementArrow: "decrementArrow",
    XCUIElement.ElementType.timeline: "timeline",
    XCUIElement.ElementType.ratingIndicator: "ratingIndicator",
    XCUIElement.ElementType.valueIndicator: "valueIndicator",
    XCUIElement.ElementType.splitGroup: "splitGroup",
    XCUIElement.ElementType.splitter: "splitter",
    XCUIElement.ElementType.relevanceIndicator: "relevanceIndicator",
    XCUIElement.ElementType.colorWell: "colorWell",
    XCUIElement.ElementType.helpTag: "helpTag",
    XCUIElement.ElementType.matte: "matte",
    XCUIElement.ElementType.dockItem: "dockItem",
    XCUIElement.ElementType.ruler: "ruler",
    XCUIElement.ElementType.rulerMarker: "rulerMarker",
    XCUIElement.ElementType.grid: "grid",
    XCUIElement.ElementType.levelIndicator: "levelIndicator",
    XCUIElement.ElementType.cell: "cell",
    XCUIElement.ElementType.layoutArea: "layoutArea",
    XCUIElement.ElementType.layoutItem: "layoutItem",
    XCUIElement.ElementType.handle: "handle",
    XCUIElement.ElementType.stepper: "stepper",
    XCUIElement.ElementType.tab: "tab",
    XCUIElement.ElementType.touchBar: "touchBar",
    XCUIElement.ElementType.statusItem: "statusItem",
  ]

  func getElementTypeName(elementType: XCUIElement.ElementType) -> String? {
    return elementTypeNames[elementType]
  }

  private let elementTypeMap = [
    XCUIElement.ElementType.any: IOSElementType.any,
    XCUIElement.ElementType.other: IOSElementType.other,
    XCUIElement.ElementType.application: IOSElementType.application,
    XCUIElement.ElementType.group: IOSElementType.group,
    XCUIElement.ElementType.window: IOSElementType.window,
    XCUIElement.ElementType.sheet: IOSElementType.sheet,
    XCUIElement.ElementType.drawer: IOSElementType.drawer,
    XCUIElement.ElementType.alert: IOSElementType.alert,
    XCUIElement.ElementType.dialog: IOSElementType.dialog,
    XCUIElement.ElementType.button: IOSElementType.button,
    XCUIElement.ElementType.radioButton: IOSElementType.radioButton,
    XCUIElement.ElementType.radioGroup: IOSElementType.radioGroup,
    XCUIElement.ElementType.checkBox: IOSElementType.checkBox,
    XCUIElement.ElementType.disclosureTriangle: IOSElementType.disclosureTriangle,
    XCUIElement.ElementType.popUpButton: IOSElementType.popUpButton,
    XCUIElement.ElementType.comboBox: IOSElementType.comboBox,
    XCUIElement.ElementType.menuButton: IOSElementType.menuButton,
    XCUIElement.ElementType.toolbarButton: IOSElementType.toolbarButton,
    XCUIElement.ElementType.popover: IOSElementType.popover,
    XCUIElement.ElementType.keyboard: IOSElementType.keyboard,
    XCUIElement.ElementType.key: IOSElementType.key,
    XCUIElement.ElementType.navigationBar: IOSElementType.navigationBar,
    XCUIElement.ElementType.tabBar: IOSElementType.tabBar,
    XCUIElement.ElementType.tabGroup: IOSElementType.tabGroup,
    XCUIElement.ElementType.toolbar: IOSElementType.toolbar,
    XCUIElement.ElementType.statusBar: IOSElementType.statusBar,
    XCUIElement.ElementType.table: IOSElementType.table,
    XCUIElement.ElementType.tableRow: IOSElementType.tableRow,
    XCUIElement.ElementType.tableColumn: IOSElementType.tableColumn,
    XCUIElement.ElementType.outline: IOSElementType.outline,
    XCUIElement.ElementType.outlineRow: IOSElementType.outlineRow,
    XCUIElement.ElementType.browser: IOSElementType.browser,
    XCUIElement.ElementType.collectionView: IOSElementType.collectionView,
    XCUIElement.ElementType.slider: IOSElementType.slider,
    XCUIElement.ElementType.pageIndicator: IOSElementType.pageIndicator,
    XCUIElement.ElementType.progressIndicator: IOSElementType.progressIndicator,
    XCUIElement.ElementType.activityIndicator: IOSElementType.activityIndicator,
    XCUIElement.ElementType.segmentedControl: IOSElementType.segmentedControl,
    XCUIElement.ElementType.picker: IOSElementType.picker,
    XCUIElement.ElementType.pickerWheel: IOSElementType.pickerWheel,
    XCUIElement.ElementType.switch: IOSElementType.switch_,
    XCUIElement.ElementType.toggle: IOSElementType.toggle,
    XCUIElement.ElementType.link: IOSElementType.link,
    XCUIElement.ElementType.image: IOSElementType.image,
    XCUIElement.ElementType.icon: IOSElementType.icon,
    XCUIElement.ElementType.searchField: IOSElementType.searchField,
    XCUIElement.ElementType.scrollView: IOSElementType.scrollView,
    XCUIElement.ElementType.scrollBar: IOSElementType.scrollBar,
    XCUIElement.ElementType.staticText: IOSElementType.staticText,
    XCUIElement.ElementType.textField: IOSElementType.textField,
    XCUIElement.ElementType.secureTextField: IOSElementType.secureTextField,
    XCUIElement.ElementType.datePicker: IOSElementType.datePicker,
    XCUIElement.ElementType.textView: IOSElementType.textView,
    XCUIElement.ElementType.menu: IOSElementType.menu,
    XCUIElement.ElementType.menuItem: IOSElementType.menuItem,
    XCUIElement.ElementType.menuBar: IOSElementType.menuBar,
    XCUIElement.ElementType.menuBarItem: IOSElementType.menuBarItem,
    XCUIElement.ElementType.map: IOSElementType.map,
    XCUIElement.ElementType.webView: IOSElementType.webView,
    XCUIElement.ElementType.incrementArrow: IOSElementType.incrementArrow,
    XCUIElement.ElementType.decrementArrow: IOSElementType.decrementArrow,
    XCUIElement.ElementType.timeline: IOSElementType.timeline,
    XCUIElement.ElementType.ratingIndicator: IOSElementType.ratingIndicator,
    XCUIElement.ElementType.valueIndicator: IOSElementType.valueIndicator,
    XCUIElement.ElementType.splitGroup: IOSElementType.splitGroup,
    XCUIElement.ElementType.splitter: IOSElementType.splitter,
    XCUIElement.ElementType.relevanceIndicator: IOSElementType.relevanceIndicator,
    XCUIElement.ElementType.colorWell: IOSElementType.colorWell,
    XCUIElement.ElementType.helpTag: IOSElementType.helpTag,
    XCUIElement.ElementType.matte: IOSElementType.matte,
    XCUIElement.ElementType.dockItem: IOSElementType.dockItem,
    XCUIElement.ElementType.ruler: IOSElementType.ruler,
    XCUIElement.ElementType.rulerMarker: IOSElementType.rulerMarker,
    XCUIElement.ElementType.grid: IOSElementType.grid,
    XCUIElement.ElementType.levelIndicator: IOSElementType.levelIndicator,
    XCUIElement.ElementType.cell: IOSElementType.cell,
    XCUIElement.ElementType.layoutArea: IOSElementType.layoutArea,
    XCUIElement.ElementType.layoutItem: IOSElementType.layoutItem,
    XCUIElement.ElementType.handle: IOSElementType.handle,
    XCUIElement.ElementType.stepper: IOSElementType.stepper,
    XCUIElement.ElementType.tab: IOSElementType.tab,
    XCUIElement.ElementType.touchBar: IOSElementType.touchBar,
    XCUIElement.ElementType.statusItem: IOSElementType.statusItem,
  ]

  func getIOSElementType(elementType: XCUIElement.ElementType) -> IOSElementType {
    return elementTypeMap[elementType]!
  }

  func getXCUIElementType(elementType: IOSElementType) -> XCUIElement.ElementType {
    return elementTypeMap.first(where: { $1 == elementType })!.key
  }
#endif
